package com.axjy.web;

import com.axjy.pojo.JiHua;
import com.axjy.service.JiHuaService;
import com.axjy.util.Log;
import com.axjy.util.Pager;
import com.axjy.web.dto.RoleMgnDto;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

/**
 * Created by Administrator on 2018/1/30.
 */
@RestController
public class JiHuaHandler {

    @Resource
    private JiHuaService jiHuaService;

    @GetMapping("/search2")
    public List<JiHua> search(String jhName){
        return jiHuaService.search2(jhName);
    }

    @PostMapping("/add2")
    public String add(JiHua jiHua){
        String m = null;
        try{
            jiHuaService.add2(jiHua);
            m="添加成功";
        }catch (Exception ex){
            m="添加失败";
            Log.logger.error(m,ex);
        }
        return m;
    }

    @PostMapping("/update2")
    public String update(JiHua jiHua){
        String m = null;
        try{
            jiHuaService.update2(jiHua);
            m="修改成功";
        }catch (Exception ex){
            m="修改失败";
            Log.logger.error(m,ex);
        }
        return m;
    }

    @PostMapping("/delete2")
    public String delete(Integer cjh_id){
        String m = null;
        try{
            jiHuaService.delete2(cjh_id);
            m="删除成功";
        }catch (Exception ex){
            m="删除失败";
            Log.logger.error(m,ex);
        }
        return m;
    }

    @GetMapping("/searchDate")
    public Pager search(@RequestParam(required = false,defaultValue = "0")Integer offset, @RequestParam(required = false,defaultValue = "4") Integer limit, RoleMgnDto dto){
        Pager pager=jiHuaService.searchPager(offset,limit,dto);
        return pager;
    }
}
